import { cacheCipher, DEFAULT_CACHE_TIME, DEFAULT_PREFIX_KEY, enableStorageEncryption } from '@/settings/encryptionSetting';

import { createStorage, CreateStorageParams } from './storageCache';

const options = {
	prefixKey: DEFAULT_PREFIX_KEY,
	key: cacheCipher.key,
	iv: cacheCipher.iv,
	hasEncrypt: enableStorageEncryption,
	timeout: DEFAULT_CACHE_TIME,
};

export const storage = createStorage(options);

export function setCache(key, value, expire) {
	storage.set(key, value, expire);
}

export function getCache(key) {
	return storage.get(key);
}

export function removeCache(key) {
	return storage.remove(key);
}

export function clearCache() {
	return storage.clear();
}